package com.fr.chart.plot;

import com.fr.base.background.IntervalColorBackground;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.chart.GeneralInfo;
import com.fr.chart.axis.CategoryAxis;
import com.fr.chart.axis.ValueAxis;
import com.fr.chart.base.equals.Equals;
import com.fr.chart.core.glyph.CategoryAxisGlyph;
import com.fr.chart.core.glyph.CategoryPlotGlyph;
import com.fr.chart.core.glyph.DateAxisGlyph;
import com.fr.chart.core.glyph.ValueAxisGlyph;
import com.fr.data.ChartData;
import java.awt.Color;
import java.awt.Insets;

public abstract class CategoryPlot extends Plot
{
  private static final long serialVersionUID = 6344220409249871761L;
  public static final double GAP_BETWEEN_PLOTS = 1.0D;
  protected CategoryAxis categoryAxis = new CategoryAxis();
  protected ValueAxis valueAxis = new ValueAxis();
  protected boolean isStacked = false;
  protected boolean bgStagger = false;
  protected Color bgColor = Color.white;

  public void install4PlotGlyph(CategoryPlotGlyph paramCategoryPlotGlyph, ChartData paramChartData)
  {
    super.install4PlotGlyph(paramCategoryPlotGlyph, paramChartData);
    paramCategoryPlotGlyph.setStacked(this.isStacked);
  }

  public void installAxisGlyph(CategoryPlotGlyph paramCategoryPlotGlyph, ChartData paramChartData)
  {
    CategoryAxisGlyph localCategoryAxisGlyph;
    ValueAxisGlyph localValueAxisGlyph = createValueAxisGlyph();
    if ((checkDate(paramChartData)) && (this.categoryAxis.isDateAxis()))
    {
      localCategoryAxisGlyph = createDateAxisGlyph();
      double[] arrayOfDouble = getDateRange(paramChartData);
      ((DateAxisGlyph)localCategoryAxisGlyph).initMinMaxValue(arrayOfDouble[0], arrayOfDouble[1]);
    }
    else
    {
      localCategoryAxisGlyph = createCategoryAxisGlyph();
    }
    paramCategoryPlotGlyph.setValueAxisGlyph(localValueAxisGlyph);
    paramCategoryPlotGlyph.setCategoryAxisGlyph(localCategoryAxisGlyph);
    int i = 0;
    int j = paramChartData.getCategoryLabelCount();
    while (i < j)
    {
      localCategoryAxisGlyph.addCategoryLabel((paramChartData.getCategoryLabel(i) == null) ? "" : paramChartData.getCategoryLabel(i));
      ++i;
    }
    localValueAxisGlyph.initMinMaxValue(getMinValueFromData(paramChartData), getMaxValueFromData(paramChartData));
    if (this.bgStagger)
    {
      IntervalColorBackground localIntervalColorBackground = new IntervalColorBackground();
      localIntervalColorBackground.setColor(getBgColor());
      localIntervalColorBackground.setPosition(this.valueAxis.getPosition());
      paramCategoryPlotGlyph.getInfo().setBackground(localIntervalColorBackground);
    }
    paramCategoryPlotGlyph.axisExtends(localCategoryAxisGlyph);
  }

  public ValueAxisGlyph createValueAxisGlyph()
  {
    return new ValueAxisGlyph(this.valueAxis);
  }

  public CategoryAxisGlyph createCategoryAxisGlyph()
  {
    return new CategoryAxisGlyph(this.categoryAxis);
  }

  public CategoryAxisGlyph createDateAxisGlyph()
  {
    return new DateAxisGlyph(this.categoryAxis);
  }

  public CategoryAxis getCategoryAxis()
  {
    return this.categoryAxis;
  }

  public void setCategoryAxis(CategoryAxis paramCategoryAxis)
  {
    this.categoryAxis = paramCategoryAxis;
  }

  public ValueAxis getValueAxis()
  {
    return this.valueAxis;
  }

  public void setValueAxis(ValueAxis paramValueAxis)
  {
    this.valueAxis = paramValueAxis;
  }

  public boolean isStacked()
  {
    return this.isStacked;
  }

  public void setIsStacked(boolean paramBoolean)
  {
    this.isStacked = paramBoolean;
  }

  public void setBgStagger(boolean paramBoolean)
  {
    this.bgStagger = paramBoolean;
  }

  public boolean getbgStagger()
  {
    return this.bgStagger;
  }

  public void setBgColor(Color paramColor)
  {
    this.bgColor = paramColor;
  }

  public Color getBgColor()
  {
    return this.bgColor;
  }

  public Insets createOuterIntsets()
  {
    return new Insets(10, 20, 20, 20);
  }

  public double getMaxValueFromData(ChartData paramChartData)
  {
    double d1 = 0.0D;
    double d2 = 0.0D;
    if (this.isStacked)
    {
      for (i = 0; i < paramChartData.getCategoryLabelCount(); ++i)
      {
        double d3 = 0.0D;
        for (int k = 0; k < paramChartData.getSeriesCount(); ++k)
        {
          Number localNumber2 = paramChartData.getValueAt(k, i);
          if ((localNumber2 != null) && (localNumber2.doubleValue() >= 0.0D))
            d3 += localNumber2.doubleValue();
        }
        d1 = (d3 > d1) ? d3 : d1;
        if (this.valueAxis.isPercentage())
        {
          double d4 = 0.0D;
          for (int l = 0; l < paramChartData.getSeriesCount(); ++l)
          {
            Number localNumber3 = paramChartData.getValueAt(l, i);
            if (localNumber3 != null)
              d4 += Math.abs(localNumber3.doubleValue());
          }
          d2 = (d3 / d4 > d2) ? d3 / d4 : d2;
        }
      }
      if (!(this.valueAxis.isPercentage()))
        break label282;
      return d2;
    }
    for (int i = 0; i < paramChartData.getCategoryLabelCount(); ++i)
      for (int j = 0; j < paramChartData.getSeriesCount(); ++j)
      {
        Number localNumber1 = paramChartData.getValueAt(j, i);
        if (localNumber1 != null)
          d1 = (localNumber1.doubleValue() > d1) ? localNumber1.doubleValue() : d1;
      }
    if (getMinValueFromData(paramChartData) == d1)
      label282: return (d1 + 10.0D);
    return d1;
  }

  public double getMinValueFromData(ChartData paramChartData)
  {
    double d1 = 0.0D;
    double d2 = 0.0D;
    if (this.isStacked)
    {
      for (i = 0; i < paramChartData.getCategoryLabelCount(); ++i)
      {
        double d3 = 0.0D;
        for (int k = 0; k < paramChartData.getSeriesCount(); ++k)
        {
          Number localNumber2 = paramChartData.getValueAt(k, i);
          if ((localNumber2 != null) && (localNumber2.doubleValue() <= 0.0D))
            d3 += localNumber2.doubleValue();
        }
        d1 = (d3 < d1) ? d3 : d1;
        if (this.valueAxis.isPercentage())
        {
          double d4 = 0.0D;
          for (int l = 0; l < paramChartData.getSeriesCount(); ++l)
          {
            Number localNumber3 = paramChartData.getValueAt(l, i);
            if (localNumber3 != null)
              d4 += Math.abs(localNumber3.doubleValue());
          }
          d2 = (d3 / d4 < d2) ? d3 / d4 : d2;
        }
      }
      if (!(this.valueAxis.isPercentage()))
        break label282;
      return d2;
    }
    for (int i = 0; i < paramChartData.getCategoryLabelCount(); ++i)
      for (int j = 0; j < paramChartData.getSeriesCount(); ++j)
      {
        Number localNumber1 = paramChartData.getValueAt(j, i);
        if (localNumber1 != null)
          d1 = (localNumber1.doubleValue() < d1) ? localNumber1.doubleValue() : d1;
      }
    label282: return d1;
  }

  public boolean match4GUI(Plot paramPlot)
  {
    boolean bool;
    if (paramPlot instanceof CategoryPlot)
      bool = ((CategoryPlot)paramPlot).getValueAxis().isPercentage();
    else
      return false;
    return ((super.match4GUI(paramPlot)) && (this.isStacked == ((CategoryPlot)paramPlot).isStacked) && (getValueAxis().isPercentage() == bool));
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    super.readXML(paramXMLableReader);
    if (paramXMLableReader.isChildNode())
    {
      String str2;
      String str1 = paramXMLableReader.getTagName();
      if ("CateAttr".equals(str1))
      {
        if ((str2 = paramXMLableReader.getAttr("isStacked")) != null)
          setIsStacked(Boolean.valueOf(str2).booleanValue());
        if ((str2 = paramXMLableReader.getAttr("bgStagger")) != null)
          setBgStagger(Boolean.valueOf(str2).booleanValue());
        if ((str2 = paramXMLableReader.getAttr("bgColor")) != null)
          setBgColor(new Color(Integer.parseInt(str2), true));
        if ((str2 = paramXMLableReader.getAttr("percentage")) != null)
          getValueAxis().setPercentage(Boolean.valueOf(str2).booleanValue());
      }
      else if ((str1.equals("CategoryAxis")) || (str1.equals("ValueAxis")) || (str1.equals("Axis")) || (str1.equals("DateAxis")))
      {
        if ((str2 = paramXMLableReader.getAttr("class")) != null)
        {
          if (str2.endsWith(".CategoryAxis"))
            this.categoryAxis = ((CategoryAxis)paramXMLableReader.readXMLObject(new CategoryAxis()));
          if (str2.endsWith(".ValueAxis"))
          {
            boolean bool = this.valueAxis.isPercentage();
            this.valueAxis = ((ValueAxis)paramXMLableReader.readXMLObject(new ValueAxis()));
            if (bool)
              this.valueAxis.setPercentage(true);
          }
        }
      }
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    super.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.startTAG("CateAttr").attr("isStacked", this.isStacked).attr("bgStagger", this.bgStagger);
    if (this.bgColor != null)
      paramXMLPrintWriter.attr("bgColor", getBgColor().getRGB());
    paramXMLPrintWriter.end();
    if (this.categoryAxis != null)
      this.categoryAxis.writeXML(paramXMLPrintWriter);
    if (this.valueAxis != null)
      this.valueAxis.writeXML(paramXMLPrintWriter);
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    CategoryPlot localCategoryPlot = (CategoryPlot)super.clone();
    if (this.categoryAxis != null)
      localCategoryPlot.categoryAxis = ((CategoryAxis)this.categoryAxis.clone());
    if (this.valueAxis != null)
      localCategoryPlot.valueAxis = ((ValueAxis)this.valueAxis.clone());
    return localCategoryPlot;
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof CategoryPlot))
      return false;
    CategoryPlot localCategoryPlot = (CategoryPlot)paramObject;
    if (!(super.equals(localCategoryPlot)))
      return false;
    if (localCategoryPlot.getbgStagger() != getbgStagger())
      return false;
    if (localCategoryPlot.isStacked() != isStacked())
      return false;
    if (!(Equals.equals(localCategoryPlot.getBgColor(), getBgColor())))
      return false;
    if (!(Equals.equals(localCategoryPlot.getCategoryAxis(), getCategoryAxis())))
      return false;
    return (Equals.equals(localCategoryPlot.valueAxis, this.valueAxis));
  }
}